import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_appgetwe/page/modelutils/video_list.dart';
import 'dart:math' as math;
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter_appgetwe/wiget/text_input.dart';

class VideoScreen extends StatefulWidget {
  @override
  _VideoScreenState createState() => _VideoScreenState();
}

class _VideoScreenState extends State<VideoScreen>
    with TickerProviderStateMixin {
  //旋转动画
  late AnimationController _controller;
  bool isAns = true;

  bool isLike = false;

  bool isfollow = true;

  bool isPlay = true;

  List<VideoList?> mapList = [
  ];

  AudioPlayer audioPlayer = AudioPlayer();

  List<Widget> pageList = [
    PageOne(),
    PageTwo(),
    PageThree(),
    PageFore(),
    PageFeign(),
    PageSix(),
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    audioPlayer.setUrl("https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/audio/y957.mp3");
    _controller = AnimationController(
      duration: const Duration(seconds: 10),
      vsync: this,
    )..repeat();

    _get();
  }

  void _get() async {
    print("get请求");
    var result = await Dio().post(
        "https://188l877k45.zicp.vip/tkVideo/api/hch/tkVideo/find/all/1/10");

    List<VideoList?> list = (result.data as List<dynamic>)
        .map((e) => VideoList.fromMap((e as Map<String, dynamic>)))
        .toList();
    setState(() {
      mapList = list;
    });

    print("打印单个");
    print(mapList[1]!.videoUrl.toString()+"-------------------------");
  }

  @override
  void dispose() {
    _controller.dispose();
    audioPlayer.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    double widthSize = MediaQuery.of(context).size.width as double; // 360.0
    double heightSize = MediaQuery.of(context).size.height as double; // 640.0
    print(widthSize.toString());
    print(heightSize.toString());
    return Scaffold(
      body: PageView.builder(
          itemCount: mapList.length == 0 ? 6 : mapList.length,
          controller: PageController(initialPage: 0, viewportFraction: 1),
          scrollDirection: Axis.vertical,
          itemBuilder: (context, index) {
            // if (index > mapList.length - 5) {
            //   _showVideoList();
            // }
            return Stack(
              children: [
                pageList[index],
                // Center(
                //   child: Text(index.toString()),
                // )
              ],
            );
          }),
    );
  }

  void _showVideoList() {}
}

class PageOne extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      //color: Colors.teal,
      decoration: BoxDecoration(
          image: DecorationImage(
              image: NetworkImage("https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/image/1000.jpg"),
              fit: BoxFit.fill)),
    );
  }
}

class PageTwo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      //color: Colors.teal,
      decoration: BoxDecoration(
          image: DecorationImage(
              image: NetworkImage("https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/image/1001.jpg"),
              fit: BoxFit.fill)),
    );
  }
}

class PageThree extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      //color: Colors.teal,
      decoration: BoxDecoration(
          image: DecorationImage(
              image: NetworkImage("https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/image/1002.jpg"),
              fit: BoxFit.fill)),
    );
  }
}

class PageFore extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      //color: Colors.teal,
      decoration: BoxDecoration(
          image: DecorationImage(
              image: NetworkImage("https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/image/1003.jpg"),
              fit: BoxFit.fill)),
    );
  }
}

class PageFeign extends StatelessWidget {
  late TextEditingController _tfEditngController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        //color: Colors.teal,
        decoration: BoxDecoration(
            image: DecorationImage(
                image: NetworkImage(
                    "https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/image/1004.jpg"),
                fit: BoxFit.fill)),
        child: Center(
          child: Container(
            width: MediaQuery.of(context).size.width - 300,
            height: MediaQuery.of(context).size.height - 700,
            //color: Colors.orange,
            child: Padding(
              padding: EdgeInsets.only(right: 50),
              child: Column(
                //mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  SizedBox(
                    height: 100,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Text(
                        "贵姓",
                        style: TextStyle(
                            fontSize: 28, fontWeight: FontWeight.w700),
                      ),
                      Container(
                        width: 300,
                        decoration: BoxDecoration(
                            //color: Colors.white,
                            borderRadius: BorderRadius.circular(15),
                            border: Border.all(
                                style: BorderStyle.solid,
                                color: Colors.white,
                                width: 3)),
                        margin: EdgeInsets.symmetric(horizontal: 20),
                        child: TextInputField(
                          controller: _tfEditngController,
                          labelText: "贵姓",
                          icon: Icons.account_circle,
                          isObscure: false,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Text(
                        "电话",
                        style: TextStyle(
                            fontSize: 28, fontWeight: FontWeight.w700),
                      ),
                      Container(
                        width: 300,
                        decoration: BoxDecoration(
                            //color: Colors.white,
                            borderRadius: BorderRadius.circular(15),
                            border: Border.all(
                                style: BorderStyle.solid,
                                color: Colors.white,
                                width: 3)),
                        margin: EdgeInsets.symmetric(horizontal: 20),
                        child: TextInputField(
                          controller: _tfEditngController,
                          labelText: "电话",
                          icon: Icons.phone,
                          isObscure: false,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Text(
                        "人数",
                        style: TextStyle(
                            fontSize: 28, fontWeight: FontWeight.w700),
                      ),
                      Container(
                        width: 300,
                        decoration: BoxDecoration(
                            //color: Colors.white,
                            borderRadius: BorderRadius.circular(15),
                            border: Border.all(
                                style: BorderStyle.solid,
                                color: Colors.white,
                                width: 3)),
                        margin: EdgeInsets.symmetric(horizontal: 20),
                        child: TextInputField(
                          controller: _tfEditngController,
                          labelText: "人数",
                          icon: Icons.supervisor_account_sharp,
                          isObscure: false,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Container(
                    width: MediaQuery.of(context).size.width,
                    color: Colors.teal,
                    alignment: Alignment.center,
                    child: Container(
                      alignment: Alignment.center,
                      width: 300,
                      height: 70,
                      decoration: BoxDecoration(
                          color: Color.fromRGBO(254, 234, 185, 1),
                          borderRadius: BorderRadius.circular(70)),
                      child: Text("提交",style: TextStyle(color: Colors.white,fontSize: 30,fontWeight: FontWeight.w700),),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ));
  }
}

class PageSix extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.height,
      //color: Colors.teal,
      decoration: BoxDecoration(
          image: DecorationImage(
              image: NetworkImage("https://gubanjie-1302851887.cos.ap-guangzhou.myqcloud.com/image/1005.jpg.jpg"),
              fit: BoxFit.fill)),
    );
  }
}
